/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package desu.bean;

import desu.nya.Anime;
import desu.nya.DAO.AnimeFactory;
import java.sql.SQLException;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author Fess
 */
@ManagedBean
@RequestScoped
public class ReqBean {
    
   
    
    /**
     * Creates a new instance of ReqBean
     */
    
    
    public ReqBean() {
    }
    
        
    public List<Anime> getAnimeOrdByPop(){
        List<Anime> list=null;
        AnimeFactory factory=null;
        factory=AnimeFactory.getInstance();
        try {
            list=factory.getAnimeDAO().getAnimeTop(10, null);
        } catch (SQLException ex) {
            ex.printStackTrace();
            FacesContext context=FacesContext.getCurrentInstance();
            context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,"Error","Get top anime failed"));
        }
        return list;
    }
    
    
    
//    public void coverUpload(){
//        String filePath="D:\\Fess\\work\\AnimeDB\\img\\"+fileId+".jpg";
//        FileInputStream file=null;
//        byte[] b=null;
//        try {
//            file = new FileInputStream(filePath);
//            if(file==null){
//                System.err.println("File Read Error");
//                return;
//            }
//            int count=file.available();
//            b=new byte[count];
//            file.read(b);
//            Cover cover=new Cover(b);
//            cover.setId(Long.valueOf(fileId));
//            factory=AnimeFactory.getInstance();
//            factory.getCoverDAO().addCover(cover);
//        } catch (FileNotFoundException ex) {
//            ex.printStackTrace();
//            System.err.println("File not Found");
//            return;
//        } catch (IOException ex){
//            ex.printStackTrace();
//            System.err.println("IO exception");
//            return;
//        } catch(SQLException ex){
//            ex.printStackTrace();
//            System.err.println("SQL Exception");
//        }
//    }
//    
    
    public void testing(){
        String str=Long.toString(100550l);
        System.err.print(str);
    }
    
    public List<String> getNickList(){
        List<String> list=null;
        try {
            AnimeFactory fact = AnimeFactory.getInstance();
            list = fact.getOtakuDAO().getAllOtaku();
            
        } catch (SQLException ex) {
            FacesContext context=FacesContext.getCurrentInstance();
            context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,"Error","Nick list get fail"));
        }
        return list;
    }
    
}
